/****************************************************
	文件：Item.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/10/13 17:4:38
	功能：三消元素 Item
*****************************************************/

using System;
using UnityEngine;
using HTUtility;
using HTFramework;

namespace HTDemo01
{
    public class Item
    {
        public int X = 0;
        public int Y = 0;

        public int PosX
        {
            get
            {
                return X * GConsts.ITEM_LENGTH;
            }
        }
        public int PosY
        {
            get
            {
                return Y * GConsts.ITEM_LENGTH;
            }
        }

        /// <summary>
        /// 元素类型
        /// </summary>
        public ItemType ItemType = ItemType.DEFAULT;

        /// <summary>
        /// 是否可以移动
        /// </summary>
        public bool CanMove
        {
            get
            {
                return ItemType != ItemType.BLOCKER;
            }
        }

        /// <summary>
        /// 实例化的 GameObject
        /// </summary>
        public GameObject Go;

        private Item mUp = null;
        private Item mDown = null;
        private Item mLeft = null;
        private Item mRight = null;
        public Item Up
        {
            get
            {
                if (Y + 1 >= LevelMap.Instance.Height) return null;
                if (mUp == null)
                {
                    mUp = LevelMap.Instance.MapData[X, Y + 1];
                }
                return mUp;
            }
        }
        public Item Down
        {
            get
            {
                if (Y - 1 < 0) return null;
                if (mDown == null)
                {
                    mDown = LevelMap.Instance.MapData[X, Y - 1];
                }
                return mDown;
            }
        }
        public Item Left
        {
            get
            {
                if (X - 1 < 0) return null;
                if (mLeft == null)
                {
                    mLeft = LevelMap.Instance.MapData[X-1, Y];
                }
                return mLeft;
            }
        }
        public Item Right
        {
            get
            {
                if (X + 1 >= LevelMap.Instance.Width) return null;
                if (mRight == null)
                {
                    mRight = LevelMap.Instance.MapData[X+1, Y];
                }
                return mRight;
            }
        }


        /// <summary>
        /// 重置（便于对象池回收）
        /// </summary>
        public void Reset()
        {
            X = Y = 0;
            ItemType = ItemType.DEFAULT;
        }
    }
}
